package com.slipper.system.codeless.controller;

import jakarta.annotation.Resource;

import com.slipper.constants.Constants;
import com.slipper.system.codeless.bo.PageButtonBO;
import com.slipper.system.codeless.service.PageButtonService;
import com.slipper.util.ResultUtil;
import com.slipper.util.Tool;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 页面内置按钮表
 */
@RestController
@RequestMapping("/system/pageButton")
public class PageButtonController {
    @Resource
    private PageButtonService pageButtonService;
    
    @PostMapping(value = "/queryBy")
    public String queryBy(@RequestBody PageButtonBO bo) {
        if(Tool.isBlank(bo.getId())) {
            return ResultUtil.failureResult("数据获取失败！");
        }
        return ResultUtil.successResult(pageButtonService.queryBy(bo.getId()));
    }

    @PostMapping(value = "/queryList")
    public String queryList(@RequestBody PageButtonBO bo) {
        return ResultUtil.successResult(pageButtonService.queryList(bo));
    }
    
    @PostMapping(value = "/queryPage")
    public String queryPage(@RequestBody PageButtonBO bo) {
        return ResultUtil.successResult(pageButtonService.queryPage(bo));
    }

    @PostMapping(value = "/save")
    public String save(@RequestBody PageButtonBO bo) {
        bo.setOperateId(Constants.getCurrentUser().getEmployeeId());
        return ResultUtil.saveResult(pageButtonService.save(bo));
    }

    @PostMapping(value = "/delete")
    public String delete(@RequestBody PageButtonBO bo) {
        return ResultUtil.deleteResult(pageButtonService.delete(bo));
    }
}
